Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

desktopApp/src/test/kotlin/org/meshtastic/desktop/di/DesktopKoinTest.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 3.61 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.desktop.di

Tff7b72import T7ee787androidx.lifecycle.SavedStateHandle
Tff7b72import T7ee787io.ktor.client.HttpClient
Tff7b72import T7ee787io.ktor.client.engine.HttpClientEngine
Tff7b72import T7ee787kotlinx.coroutines.CoroutineDispatcher
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787org.koin.core.annotation.KoinExperimentalAPI
Tff7b72import T7ee787org.koin.dsl.koinApplication
Tff7b72import T7ee787org.koin.dsl.module
Tff7b72import T7ee787org.koin.dsl.onClose
Tff7b72import T7ee787org.koin.test.verify.verify
Tff7b72import T7ee787org.meshtastic.core.ble.BleLogFormat
Tff7b72import T7ee787org.meshtastic.core.ble.BleLogLevel
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertTrue

Tf0883e@OptInTb4b4b4(Te6edf3KoinExperimentalAPITff7b72::Te6edf3classTb4b4b4)
Tff7b72class T56d364DesktopKoinTest Tb4b4b4{

Tf0883e@Test
Tff7b72fun Td2a8ff`verify desktop koin modules`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// This test validates the full Koin DI graph for the Desktop target.
T8b949e// It includes the main desktopModule (repositories, use cases, ViewModels, stubs)
T8b949e// and the desktopPlatformModule (DataStores, Room database, lifecycle).
Te6edf3module Tb4b4b4{ Te6edf3includesTb4b4b4(Te6edf3desktopModuleTb4b4b4(Tb4b4b4)Tb4b4b4, Te6edf3desktopPlatformModuleTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4}
Tb4b4b4.Te6edf3verifyTb4b4b4(
Te6edf3extraTypes Tff7b72=
Te6edf3listOfTb4b4b4(
Te6edf3SavedStateHandleTff7b72::Te6edf3classTb4b4b4,
Te6edf3CoroutineDispatcherTff7b72::Te6edf3classTb4b4b4,
T8b949e// MeshBeaconRepository is built by a factory function that supplies an
T8b949e// ApplicationCoroutineScope. Koin Verify introspects the class constructor anyway, so its
T8b949e// plain CoroutineScope parameter has to be declared even though nothing resolves it.
Te6edf3CoroutineScopeTff7b72::Te6edf3classTb4b4b4,
Te6edf3HttpClientTff7b72::Te6edf3classTb4b4b4,
Te6edf3HttpClientEngineTff7b72::Te6edf3classTb4b4b4,
T8b949e// BleLoggingConfig is a data class assembled by a factory function. Koin Verify
T8b949e// still introspects its constructor params, so the wrapping enums need to be
T8b949e// declared as known types even though they're never resolved from the graph.
Te6edf3BleLogLevelTff7b72::Te6edf3classTb4b4b4,
Te6edf3BleLogFormatTff7b72::Te6edf3classTb4b4b4,
Tb4b4b4)Tb4b4b4,
Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`closing a koin container fires onClose for instantiated singles`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Pins the mechanism desktopModule() relies on: LinuxNotificationSender's native teardown
T8b949e// (notify_uninit) runs only because Koin invokes onClose when the container closes, which
T8b949e// Main.kt triggers via stopKoin() once the Compose application loop returns. A Koin upgrade
T8b949e// that changed this would silently reinstate the leak, so it is asserted rather than assumed.
Tff7b72var Te6edf3closed Tff7b72= Tff7b72false
Tff7b72val Te6edf3app Tff7b72= Te6edf3koinApplication Tb4b4b4{
Te6edf3modulesTb4b4b4(Te6edf3module Tb4b4b4{ Te6edf3singleTff7b72<Te6edf3AutoCloseableTff7b72> Tb4b4b4{ Te6edf3AutoCloseable Tb4b4b4{ Te6edf3closed Tff7b72= Tff7b72true Tb4b4b4} Tb4b4b4}Tb4b4b4.Te6edf3onClose Tb4b4b4{ Tffa657itTff7b72?.Te6edf3closeTb4b4b4(Tb4b4b4) Tb4b4b4} Tb4b4b4}Tb4b4b4)
Tb4b4b4}
Te6edf3appTb4b4b4.Te6edf3koinTb4b4b4.Te6edf3getTff7b72<Te6edf3AutoCloseableTff7b72>Tb4b4b4(Tb4b4b4) T8b949e// onClose only fires for singles that were actually instantiated
Te6edf3appTb4b4b4.Te6edf3closeTb4b4b4(Tb4b4b4)

Te6edf3assertTrueTb4b4b4(Te6edf3closedTb4b4b4, Ta5d6ff"Ta5d6ffExpected Koin to invoke onClose when the container is closedTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s